﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using frag_boardgame;

namespace frag_testproject
{
    /// <summary>
    /// Summary description for AItest
    /// </summary>
    [TestClass]
    public class AItest
    {
        public AItest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void AddAIPlayer()
        {
            Configuraion conf = new Configuraion();
            Game game = new Game();
            conf.addPlayer(new PlayerConfiguration(0, 0, "Roger", Player.Controller.AI));
            conf.addPlayer(new PlayerConfiguration(2, 2, "Jesica", Player.Controller.Human));
            conf.addPlayer(new PlayerConfiguration(5, 5, "Bob"));
            game.New(conf);
            Board board = game.Data.Board;
            Assert.AreEqual(game.Data.GetPlayersList().ElementAt(0).Control, Player.Controller.AI);
            Assert.AreEqual(game.Data.GetPlayersList().ElementAt(1).Control, Player.Controller.Human);
            Assert.AreEqual(game.Data.GetPlayersList().ElementAt(2).Control, Player.Controller.Human);
        }

        [TestMethod]
        public void ChooseTarget()
        {
            //this test is removed since the game.New already checks this functionality
            /*
            Configuraion conf = new Configuraion();
            Game game = new Game();
            conf.addPlayer(new PlayerConfiguration(0, 0, "Roger", 3, Player.Controller.AI));
            conf.addPlayer(new PlayerConfiguration(0, 6, "Jesica", 3));
            conf.addPlayer(new PlayerConfiguration(5, 0, "Bob", 3));
            game.New(conf);
            Board board = game.Data.Board;
            Player target = AI.ChooseTarget(game.Data.GetPlayersList().ElementAt(0), game);
            Assert.AreEqual(target, game.Data.GetPlayersList().ElementAt(2));

            game.Data.Board.GetSquare(3, 0).AddWall(SquareWalls.Down);
            target = AI.ChooseTarget(game.Data.GetPlayersList().ElementAt(0), game);
            Assert.AreEqual(target, game.Data.GetPlayersList().ElementAt(1));

            game.Data.Board.GetSquare(0, 3).AddWall(SquareWalls.Right);
            target = AI.ChooseTarget(game.Data.GetPlayersList().ElementAt(0), game);
            Assert.AreEqual(target, game.Data.GetPlayersList().ElementAt(2));
            */
        }

        [TestMethod]
        public void MoveTowardsTarget()
        {
            //this test is removed since the game.New already checks this functionality
            /*
            Configuraion conf = new Configuraion();
            Game game = new Game();
            conf.addPlayer(new PlayerConfiguration(0, 0, "Roger", 3, Player.Controller.AI));
            conf.addPlayer(new PlayerConfiguration(2, 10, "Jesica", 3));
            game.New(conf);
            Board board = game.Data.Board;
            game.Data.GetPlayersList().ElementAt(0).MovesLeft = 20;
            Player target = AI.ChooseTarget(game.Data.GetPlayersList().ElementAt(0), game);
            Player player = game.Data.GetPlayersList().ElementAt(0);
            float distBefore = player.calculateDistance(target,game.Data);
            AI.MoveToTarget(player, target, game);
            float distAfter = player.calculateDistance(target,game.Data);
            Assert.IsTrue(distBefore > distAfter);

            board.GetSquare(0, 3).AddWall(SquareWalls.Right);
            board.GetSquare(player.Row, player.Column).player = null;
            player.Row = 0;
            player.Column = 0;
            board.GetSquare(player.Row, player.Column).player = player;
            player.MovesLeft = 20;
            AI.MoveToTarget(player, target, game);
            Assert.IsTrue(player.Row ==2);
            */
        }

        [TestMethod]
        public void ShootTarget()
        {
            //this test is removed since the game.New already checks this functionality
            /*
            Configuraion conf = new Configuraion();
            Game game = new Game();
            conf.addPlayer(new PlayerConfiguration(0, 0, "Roger", 3, Player.Controller.AI));
            conf.addPlayer(new PlayerConfiguration(0, 6, "Jesica", 3));
            game.New(conf);
            Board board = game.Data.Board;
            game.Data.GetPlayersList().ElementAt(0).MovesLeft = 20;
            Player target = AI.ChooseTarget(game.Data.GetPlayersList().ElementAt(0), game);
            Player player = game.Data.GetPlayersList().ElementAt(0);
            int before = player.ShotsLeft;
            AI.ShotTarget(target, game);
            int after = player.ShotsLeft;
            Assert.AreEqual(before, after + 1);
            */
        }

        [TestMethod]
        public void AIPlay()
        {
            Configuraion conf = new Configuraion();
            Game game = new Game();
            conf.addPlayer(new PlayerConfiguration(0, 0, "Roger", Player.Controller.AI));
            conf.addPlayer(new PlayerConfiguration(0, 11, "Jesica"));
            game.New(conf);
            game.Data.Board.GetSquare(0, 0).AddWall(SquareWalls.Right);
            game.Data.Board.GetSquare(0, 0).AddWall(SquareWalls.Down);
            game.StartGame();
            game.Data.GetPlayersList().ElementAt(0).MovesLeft = 20;
            Player target = AI.ChooseTarget(game.Data.GetPlayersList().ElementAt(0), game);
            Player player = game.Data.GetPlayersList().ElementAt(0);
            AI.PlayAI(game);
            //Assert.AreEqual(player.ShotsLeft, 0);
            Assert.AreNotEqual(game.Data.CurrentPlayer, player);

        }
    }
}
